<?php

namespace app\common\func;


use app\common\model\UserAddress;
use fast\Random;

class Order
{

    public static function getOrderByOrderNum($orderNum){
        return \app\common\model\Order::where(["order_num" => $orderNum])->find();
    }

    public static function getOrderById($orderId){
        return \app\common\model\Order::get($orderId);
    }

    public static function getUserAddressById($userId,$addressId){
        return UserAddress::where(["user_id" => $userId,"id" => $addressId])->find();
    }

    public static function getOrderNum(){
        return "MAX".date("YmdHis").Random::numeric(6);
    }

    public static function getUserAddress($userId){
        return UserAddress::where(["user_id" => $userId])->order("default desc")->select();
    }

    public static function getUserDefaultAddress($userId){
        return UserAddress::where(["user_id" => $userId,"default" => 1])->select();
    }
}
